package com.hxzy.controller.monitor;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hxzy.common.annotation.Log;
import com.hxzy.common.core.controller.BaseController;
import com.hxzy.common.core.domain.R;
import com.hxzy.common.core.domain.page.TableDataInfo;
import com.hxzy.common.enums.BusinessType;
import com.hxzy.common.utils.poi.ExcelUtil;
import com.hxzy.system.domain.SysOperLog;
import com.hxzy.system.domain.dto.SysOperLogSearchDTO;
import com.hxzy.system.service.ISysOperLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 操作日志记录
 * 
 * @author
 */
@Api(tags = "操作日志API")
@RestController
@RequestMapping("/api/monitor/operlog")
public class SysOperlogController extends BaseController
{
    @Autowired
    private ISysOperLogService operLogService;

    @ApiOperation(value = "操作日志查询")
    @PreAuthorize("@hxzy.hasPermi('monitor:operlog:list')")
    @GetMapping("/list")
    public R list(SysOperLogSearchDTO sysOperLogSearchDTO)
    {
        IPage<SysOperLog> page = operLogService.search(sysOperLogSearchDTO);
        return super.pageVO(page);
    }

    @ApiOperation(value = "导出Excel")
    @Log(title = "操作日志", businessType = BusinessType.EXPORT)
    @PreAuthorize("@hxzy.hasPermi('monitor:operlog:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysOperLogSearchDTO sysOperLogSearchDTO)
    {
        List<SysOperLog> list = operLogService.searchExport(sysOperLogSearchDTO);
        ExcelUtil<SysOperLog> util = new ExcelUtil<SysOperLog>(SysOperLog.class);
        util.exportExcel(response, list, "操作日志");
    }

    @ApiOperation(value = "删除日志")
    @Log(title = "操作日志", businessType = BusinessType.DELETE)
    @PreAuthorize("@hxzy.hasPermi('monitor:operlog:remove')")
    @DeleteMapping("/{operIds}")
    public R remove(@PathVariable Long[] operIds)
    {
        return toAjax(operLogService.deleteOperLogByIds(operIds));
    }

    @ApiOperation(value = "清空所有日志")
    @Log(title = "操作日志", businessType = BusinessType.CLEAN)
    @PreAuthorize("@hxzy.hasPermi('monitor:operlog:remove')")
    @DeleteMapping("/clean")
    public R clean()
    {
        operLogService.cleanOperLog();
        return R.ok();
    }
}
